package models

import (
	"time"

	"go.mongodb.org/mongo-driver/bson/primitive"
)

// TransactionStats 交易统计数据模型
type TransactionStats struct {
	ID         primitive.ObjectID `bson:"_id,omitempty" json:"id"`
	Month      string             `bson:"month" json:"month"` // 月份，格式：YYYY-MM
	CreatedAt  time.Time          `bson:"created_at" json:"created_at"`
	UpdatedAt  time.Time          `bson:"updated_at" json:"updated_at"`
	Statistics StatisticsData     `bson:"statistics" json:"statistics"`
}

// StatisticsData 统计数据内容
type StatisticsData struct {
	TotalTransactions        int64              `bson:"totaltransactions" json:"total_transactions"`
	TotalAmountUSD           float64            `bson:"totalamountusd" json:"total_amount_usd"`
	CurrencyDistributionUSD  map[string]float64 `bson:"currencydistributionusd" json:"currency_distribution_usd"`
	CurrencyPercentage       map[string]float64 `bson:"currencypercentage" json:"currency_percentage"`
	TypeDistribution         map[string]int64   `bson:"typedistribution" json:"type_distribution"`
	TypePercentage           map[string]float64 `bson:"typepercentage" json:"type_percentage"`
	TypeAmountDistribution   map[string]float64 `bson:"typeamountdistribution" json:"type_amount_distribution"`
	TypeAmountPercentage     map[string]float64 `bson:"typeamountpercentage" json:"type_amount_percentage"`
	TotalFeeDeductionAmount  float64            `bson:"totalfeedeductionamount" json:"total_fee_deduction_amount"`
	FeeTypeDistributionUSD   map[string]float64 `bson:"feetypedistributionusd" json:"fee_type_distribution_usd"`
	FeeTypePercentage        map[string]float64 `bson:"feetypepercentage" json:"fee_type_percentage"`
	TotalFeeReturnAmount     float64            `bson:"totalfeereturnamount" json:"total_fee_return_amount"`
	FeeRatePercentage        float64            `bson:"feeratepercentage" json:"fee_rate_percentage"`
	FeeReturnRatePercentage  float64            `bson:"feereturnratepercentage" json:"fee_return_rate_percentage"`
	TotalRechargeAmountUSD   float64            `bson:"totalrechargeamountusd" json:"total_recharge_amount_usd"`
	TotalAuthAmountUSD       float64            `bson:"totalauthamountusd" json:"total_auth_amount_usd"`
	NetFundChangeUSD         float64            `bson:"netfundchangeusd" json:"net_fund_change_usd"`
	MaxCardDayTxnCount       int64              `bson:"maxcarddaytxncount" json:"max_card_day_txn_count"`
	MaxCardDayTxnAmount      float64            `bson:"maxcarddaytxnamount" json:"max_card_day_txn_amount"`
	TransactionAmountCV      float64            `bson:"transactionamountcv" json:"transaction_amount_cv"`
	OffHoursTxnPercentage    float64            `bson:"offhourstxnpercentage" json:"off_hours_txn_percentage"`
	RefundVoidTxnPercentage  float64            `bson:"refundvoidtxnpercentage" json:"refund_void_txn_percentage"`
	CrossBorderTxnPercentage float64            `bson:"crossbordertxnpercentage" json:"cross_border_txn_percentage"`
	HighRiskMCCTxnPercentage float64            `bson:"highriskmcctxnpercentage" json:"high_risk_mcc_txn_percentage"`
}

// TransactionStatsQuery 查询参数
type TransactionStatsQuery struct {
	Month     string `json:"month" form:"month"`           // 月份，格式：YYYY-MM
	StartDate string `json:"start_date" form:"start_date"` // 开始日期
	EndDate   string `json:"end_date" form:"end_date"`     // 结束日期
	Limit     int64  `json:"limit" form:"limit"`           // 限制数量
	Offset    int64  `json:"offset" form:"offset"`         // 偏移量
}

// TransactionStatsResponse 响应结构
type TransactionStatsResponse struct {
	Total   int64              `json:"total"`
	Data    []TransactionStats `json:"data"`
	Summary StatisticsData     `json:"summary"`
}

// DashboardData 数据看板数据
type DashboardData struct {
	Overview     DashboardOverview     `json:"overview"`
	Trends       DashboardTrends       `json:"trends"`
	Distribution DashboardDistribution `json:"distribution"`
	Performance  DashboardPerformance  `json:"performance"`
}

// DashboardOverview 概览数据
type DashboardOverview struct {
	TotalTransactions  int64   `json:"total_transactions"`
	TotalAmountUSD     float64 `json:"total_amount_usd"`
	NetFundChangeUSD   float64 `json:"net_fund_change_usd"`
	SuccessRate        float64 `json:"success_rate"`
	AverageTransaction float64 `json:"average_transaction"`
	TotalCards         int64   `json:"total_cards"`
	ActiveCards        int64   `json:"active_cards"`
}

// DashboardTrends 趋势数据
type DashboardTrends struct {
	DailyStats   []DailyStats   `json:"daily_stats"`
	MonthlyStats []MonthlyStats `json:"monthly_stats"`
}

// DailyStats 每日统计
type DailyStats struct {
	Date           string  `json:"date"`
	Transactions   int64   `json:"transactions"`
	Amount         float64 `json:"amount"`
	RechargeAmount float64 `json:"recharge_amount"`
	AuthAmount     float64 `json:"auth_amount"`
	RefundAmount   float64 `json:"refund_amount"`
	VoidAmount     float64 `json:"void_amount"`
}

// MonthlyStats 每月统计
type MonthlyStats struct {
	Month          string  `json:"month"`
	Transactions   int64   `json:"transactions"`
	Amount         float64 `json:"amount"`
	RechargeAmount float64 `json:"recharge_amount"`
	AuthAmount     float64 `json:"auth_amount"`
	RefundAmount   float64 `json:"refund_amount"`
	VoidAmount     float64 `json:"void_amount"`
}

// DashboardDistribution 分布数据
type DashboardDistribution struct {
	CurrencyDistribution map[string]float64 `json:"currency_distribution"`
	TypeDistribution     map[string]int64   `json:"type_distribution"`
	AmountDistribution   map[string]float64 `json:"amount_distribution"`
}

// DashboardPerformance 性能数据
type DashboardPerformance struct {
	OffHoursPercentage    float64 `json:"off_hours_percentage"`
	CrossBorderPercentage float64 `json:"cross_border_percentage"`
	HighRiskMCCPercentage float64 `json:"high_risk_mcc_percentage"`
	RefundVoidPercentage  float64 `json:"refund_void_percentage"`
	TransactionAmountCV   float64 `json:"transaction_amount_cv"`
	MaxCardDayTxnCount    int64   `json:"max_card_day_txn_count"`
	MaxCardDayTxnAmount   float64 `json:"max_card_day_txn_amount"`
}
